<?php


namespace app\admin\controller;


use app\admin\validate\AuthValidate;
use app\BaseController;
use app\Code;
use app\lib\exception\ServiceException;
use app\service\AuthService;
use think\App;
use think\exception\ValidateException;

class AuthController extends BaseController
{
    private $service;

    public function __construct(App $app)
    {
        $this->service = new AuthService();
        parent::__construct($app);
    }

    public function adminLogin(){
        $param = $this->request->param(['username', 'password']);

        validate(AuthValidate::class)
            ->scene('WxLogin')
            ->check($param);

        $result = $this->service->adminLogin($param['username'], $param['password']);

        return $this->returnJson(['token' => $result['token'], 'user' => $result['user']]);
    }
}
